package com.zht.demo;

import org.apache.commons.collections4.CollectionUtils;

import java.lang.reflect.Array;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

public class AgeCalculator {

    public static void main(String[] args) {
//        String idCardNumber = "37020319710624902X"; // 例：身份证号码
//
//        if (isAdult(idCardNumber)) {
//            System.out.println("成年");
//        } else {
//            System.out.println("未成年");
//        }

        //测试循环
        int a = 10;
        do {
            System.out.println(a);
            a++;
        }while (a < 20);

        System.out.println("-----------------------------------------");

        int b = 50;
        while (b < 80){
            System.out.println(b);
            b++;
        }

        //测试switch
        int c = 5;
        switch (c){
            case 1:
                System.out.println("1触发了");
            case 2:
                System.out.println("2触发了");
            case 3:
                System.out.println("3触发了");
            case 4:
                System.out.println("4触发了");
            case 5:
                System.out.println("5触发了");
        }


//        String[] strings = {"100000","20000.10","3111","48787.4"};
//        List<String> strings1 = Arrays.asList(strings);
//        String collect = Arrays.stream(strings).collect(Collectors.joining("---"));
//        System.out.println(collect);
/*
        double sum = strings1.stream().mapToDouble(Double::parseDouble).sum();
        System.out.println(sum);
*/
    }

    public static boolean isAdult(String idCardNumber) {
        // 获取身份证中的出生日期
        String birthDateStr = idCardNumber.substring(6, 14);
        
        // 格式化日期字符串
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        try {
            Date birthDate = dateFormat.parse(birthDateStr);
            Date currentDate = new Date();
            
            // 比较出生日期和当前日期，判断是否成年（18岁以上）
            long ageInMillis = currentDate.getTime() - birthDate.getTime();
            long ageInYears = ageInMillis / (1000L * 60 * 60 * 24 * 365); // 毫秒转换成年
            
            return ageInYears >= 18;
        } catch (ParseException e) {
            e.printStackTrace();
            return false;
        }
    }
}
